local hopForward = function()
  local hop = require "hop"
  local directions = require("hop.hint").HintDirection
  hop.hint_char1 { direction = directions.AFTER_CURSOR, current_line_only = false }
end

local hopBackward = function()
  local hop = require "hop"
  local directions = require("hop.hint").HintDirection
  hop.hint_char1 { direction = directions.BEFORE_CURSOR, current_line_only = false }
end

return {
  "AstroNvim/astrocore",
  opts = {
    mappings = {
      i = {
        ["jk"] = { "<ESC>" },
        ["<C-h>"] = { "<Left>" },
        ["<C-j>"] = { "<Down>" },
        ["<C-k>"] = { "<Up>" },
        ["<C-l>"] = { "<Right>" },
        ["<C-a>"] = { "<Home>" },
        ["<C-e>"] = { "<End>" },
        ["<C-d>"] = { "<Delete>" },
      },

      n = {
        ["<leader>s"] = { "<cmd>w<cr>" },
        ["<Tab>"] = {
          function() require("astrocore.buffer").nav(vim.v.count1) end,
          desc = "Next buffer",
        },
        ["<S-Tab>"] = {
          function() require("astrocore.buffer").nav(-vim.v.count1) end,
          desc = "Previous buffer",
        },
        ["<leader>mp"] = { "<Plug>MarkdownPreview" },
        ["U"] = { "<C-u>" },
        ["D"] = { "<C-d>" },
        ["Y"] = { "y$" },
        ["L"] = { "$" },
        ["H"] = { "^" },
        [";"] = { ":" },
        ["j"] = { "gj" },
        ["k"] = { "gk" },
        ["<C-h>"] = { "<C-w><Left>" },
        ["<C-l>"] = { "<C-w><Right>" },
        ["<C-j>"] = { "<C-w><Down>" },
        ["<C-k>"] = { "<C-w><Up>" },
        ["ca"] = {
          function() vim.lsp.buf.code_action() end,
          desc = "LSP code action",
        },
        ["<leader><leader>b"] = {
          hopBackward,
          desc = "Hop Easymotion - Find Forward",
        },
        ["<leader><leader>w"] = {
          hopForward,
          desc = "Hop Easymotion - Find Forward",
        },
        ["=="] = {
          function() vim.lsp.buf.format() end,
          desc = "Format file",
        },
      },
      v = {
        ["L"] = { "$" },
        ["H"] = { "^" },
        ["J"] = { ":m '>+1<CR>gv=gv" },
        ["K"] = { ":m '<-2<CR>gv=gv" },
      },
    },
  },
}
